/*
 *说明：登录日志 首页脚本
 *
 *@author liuxun 2012-04-06
*/

var opeForm;
var loginLogGrid;
var sessionLogGrid;
var cmdLogGrid;

var loginLogId;
var sessionLogId;

$(function(){
	
	opeForm = $('#opeForm');
	$("#tabs").tabs({}); 
	
	loginLogGrid=$('#loginLogTable').datagrid({
		columns:[[

		    {title:'机构名称',field:'ORG_NAME',align:'center',width:150},

		    {title:'统一登录名',field:'LOGIN_NAME',align:'center',width:80},
           
            {title:'用户姓名',field:'USR_NAME',align:'center',width:80},

            {title:'登入时间',field:'BEGIN_TIME',align:'center',width:150},
            
            {title:'登出时间',field:'END_TIME',align:'center',width:150},
            
            {title:'节点名称',field:'NODE_NAME',align:'center',width:120},
            
            {title:'节点 IP',field:'NODE_IP',align:'center',width:120},
            
            {title:'客户端IP',field:'CLIENT_IP',align:'center',width:120}
        ]],
		pagination:true,
		singleSelect: true,
		onClickRow: function(rowIndex, rowData) {
			var selectedLoginLogId = rowData.LOGIN_LOG_ID;
			querySessionLogOperation(selectedLoginLogId);
	    }
	});
	
	sessionLogGrid=$('#sessionLogTable').datagrid({
		columns:[[

		    {title:'资源名称',field:'RSC_NAME',align:'center',width:120},
            
		    {title:'账号名',field:'RSC_ACC_ID',align:'center',width:80},

            {title:'协议',field:'PRO_NAME',align:'center',width:80},
            
		    {title:'开始时间',field:'BEGIN_TIME',align:'center',width:150},
	          
		    {title:'结束时间',field:'END_TIME',align:'center',width:150},

            {title:'管理IP',field:'MANAGE_IP',align:'center',width:120},
 
            {title:'服务IP',field:'SERVICE_IP',align:'center',width:120},
          
            {title:'节点 IP',field:'NODE_IP',align:'center',width:120},

			{title:'操作',field:'operation',align:'center',width:60,
	        	formatter:function(value,rec){
	        		if(rec.END_TIME == null || rec.END_TIME == ''){
		        	    return '';	        			
	        		}else{
	             		var s = '<a style="cursor:pointer; color:blue" onclick=\'showPlayback("' + rec.SESSION_LOG_ID + '")\'>回放</a>';
		        	    return s;
	        		}
		   		}
		    }
        ]],
		pagination:true,
		singleSelect: true,
		onClickRow: function(rowIndex, rowData) {
			var selectedSessionLogId = rowData.SESSION_LOG_ID;
			queryCmdLogOperation(selectedSessionLogId);
	    }
	});
	
	cmdLogGrid=$('#cmdLogTable').datagrid({
		columns:[[

            {title:'开始时间',field:'BEGIN_TIME',align:'center',width:200},

            {title:'命令',field:'CMD',align:'center',width:450}
        ]],
		pagination:true,
		singleSelect: false
	});

	queryLoginOperation();

	$('#queryBtn').click(queryLoginOperation);
	$('#clearBtn').click(clearOperation);
	$('#clearBtnSession').click(clearOperation);
	$('#reloadBtn').click(refreshWin);
	$('#genReportBtn').click(genReporOperation);
	
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryLoginOperation(){
	var params = opeForm.serializeObject();
	loginLogGrid.datagrid("options").pageNumber = 1;
	loginLogGrid.datagrid({
		url: 'E_LOGIN_LOG!queryList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//查询会话日志操作
function querySessionLogOperation(selectedLoginLogId){
	$('#genReportBtnSession').click(genReporSessionOperation);
	loginLogId = selectedLoginLogId;
	var params = opeForm.serializeObject();
	sessionLogGrid.datagrid("options").pageNumber = 1;
	sessionLogGrid.datagrid({
		url: 'E_SESSION_LOG!queryList.do?modelMap.login_log_id=' + selectedLoginLogId
	});
}

//查询命令日志操作
function queryCmdLogOperation(selectedSessionLogId){
	$('#genReportBtnCmd').click(genReporCmdOperation);
	sessionLogId = selectedSessionLogId;
	var params = opeForm.serializeObject();
	cmdLogGrid.datagrid("options").pageNumber = 1;
	cmdLogGrid.datagrid({
		url: 'E_CMD_LOG!queryList.do?modelMap.session_log_id=' + selectedSessionLogId
	});
}

//显示回放页面
function showPlayback(key) {
	var url = 'E_SESSION_LOG!showPlayback.do?model.key=' + key;
	openWin(url,'pop','','','','','yes'); 
}

//显示监控页面
function showSupervisory(key){
	var url = 'E_SESSION_LOG!showSupervisory.do?model.key=' + key;
	openWin(url,'pop','','','','','yes'); 
}

//生成登录日志报表
function genReporOperation(){	
	opeForm.attr('action', 'E_LOGIN_LOG!genLoginLogReport.do');
	opeForm.submit();
}

//根据登录日志生成会话日志报表
function genReporSessionOperation(){
	var url = 'E_SESSION_LOG!genLoginSessionLogReport.do?model.login_log_id='+loginLogId;
	openWin(url,'pop');
}

//根据会话日志生成命令日志报表
function genReporCmdOperation(){
	var url = 'E_CMD_LOG!genLoginSessionCmdLogReport.do?model.session_log_id='+sessionLogId;
	openWin(url,'pop');
}

//操作成功后刷新列表
function afterOK(){
	queryOperation();
}